package com.dhcc.core.modules.system.warpper;

import java.util.List;
import java.util.Map;

import com.dhcc.core.config.properties.SysProperties;
import com.dhcc.core.framework.base.warpper.BaseControllerWarpper;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.modules.system.cache.dict.DictCache;
import com.dhcc.core.modules.system.entity.Dict;

/**
 * 字典列表的包装
 *
 * @ClassName: DictWarpper
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午10:43:21
 */
public class DictWarpper extends BaseControllerWarpper {

    public DictWarpper(Object list) {
        super(list);
    }


    @Override
    public void warpTheMap(Map<String, Object> map) {
        StringBuffer detail = new StringBuffer();
        Long id = (Long) map.get("id");
        List<Dict> dicts = DictCache.me().findDictsByPId(id);
        if (dicts != null) {
            for (Dict dict : dicts) {
                detail.append(dict.getKey() + ":" + dict.getName() + ",");
            }
            map.put("detail", CommonUtil.removeSuffix(detail.toString(), ","));
        }
        Long categoryId = (Long) map.get("categoryId");
        if(categoryId==0){
            map.put("categoryName", SysProperties.me().getOrgFullName());
        }else{
            map.put("categoryName", DictCache.me().getCategoryNameById(id));
        }
    }

}
